<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.queryCondition" allow-clear placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="default"
        rowKey="key"
        :pagination="pagination"
        @change="handleTableChange"
        :columns="columns"
        :data-source="loadData"
      >
        <span slot="out" slot-scope="text, record">
          <template>
            <a-tag color="#D15B47" @click="handleOutStore(record)">调出</a-tag>
          </template>
        </span>
        <span slot="in" slot-scope="text, record">
          <template>
            <a-tag color="#87B87F" @click="handleInStore(record)">调入</a-tag>
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>
  
<script>
import { getStoreListUsingPOST } from '@/api/api/mendianguanli.ts'
export default {
  name: 'ShiftPhone',
  data() {
    return {
      mdl: null,
      visible: false,
      value: '',
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      pagination: {
        total: 0,
      },
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        queryCondition: '',
        status: '',
      },
      // 表头
      columns: [
        {
          title: '店面名称',
          dataIndex: 'storeName',
        },
        {
          title: '调出',
          dataIndex: 'out',
          width: '220px',
          scopedSlots: { customRender: 'out' },
        },
        {
          title: '调入',
          dataIndex: 'in',
          width: '220px',
          scopedSlots: { customRender: 'in' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
    }
  },
  mounted() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch(params) {
      getStoreListUsingPOST(params)
        .then((res) => {
          this.loadData = res.data.list
          this.queryParam.pageNo = this.pagination.current
          this.pagination = { ...this.pagination, total: Number(res.data.total) }
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
    pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.handleSearch({
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
        pageNo: pagination.current,
        pageSize: pagination.pageSize,
        queryCondition: this.queryParam.queryCondition,
        status: this.queryParam.status,
        date: this.queryParam.date,
      })
    },
    handleOutStore(record) {
      this.$router.push({ 
        path: `/report/shiftPhoneShop/${record?.id}`,
        query: {outStoreId: record.id}, 
        })
    },
    handleInStore(record) {
      this.$router.push({ 
        path: `/report/shiftPhoneShop/${record?.id}`,
        query: {inStoreId: record.id}, 
        })
    },
    handleBoth(record) {
      this.mdl = { ...record }
      this.visible = true
    },
    handleOk() {
      this.visible = false
      this.confirmLoading = true
      setTimeout(() => {
        this.confirmLoading = false
      }, 1000)
      this.$message.success('操作成功')
    },
    handleCancel() {
      this.visible = false
      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
  },
}
</script>